import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App'
import { List,Button,Dialog,Switch,Search,Toast,Tabbar,TabbarItem,Tab,Icon,NavBar,Tabs,Stepper,Picker,Form,Field,Popup,DatetimePicker,Overlay,Loading} from 'vant';
import Http from './service'
import routes from './router'
import store from './store'

Vue.use(List)

Vue.use(VueRouter)
Vue.use(Button)
Vue.use(Toast);
Vue.use(Tabbar);
Vue.use(TabbarItem);
Vue.use(Icon);
Vue.use(NavBar);
Vue.use(Picker);
Vue.use(Form);
Vue.use(Field);
Vue.use(Popup);
Vue.use(DatetimePicker);
Vue.use(Stepper);
Vue.use(Tabs);
Vue.use(Tab);
Vue.use(Overlay);
Vue.use(Loading);
Vue.use(Dialog);
Vue.use(Search);
Vue.use(Switch);




Vue.prototype.$http = new Http();

Vue.config.productionTip = false
const router = new VueRouter({
  routes 
})

//拦截器
router.beforeEach((route, redirect, next) => {
  console.log(localStorage.getItem("token")!=null&&localStorage.getItem("token")!="",route.path);
 if (localStorage.getItem("token")!=null&&localStorage.getItem("token")!="") {
  if(route.path != '/'){
    next()
  }else{
    next({
      path: '/index',
      query: {redirect:route.fullPath}
     }) 
    }
} else {
  console.log("--->1",route)
  if(route.path == '/'){
    next()
  }else{
    next({
      path: '/',
      query: {redirect:route.fullPath}
     }) 
    }
 }
  
})

export default  new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
